# requess模块处理cookie相关的请求
# requests处理cookie的方法:2.cookies参数的使用
import requests

url = "https://user.qzone.qq.com/1439237913"

# 登录后从浏览器中复制User-Agent和Cookie
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36"
}

# 构造cookies字典
cookie_str = "pgv_pvid=5148731955; pgv_pvi=7338438656; ptui_loginuin=1439237913; RK=7yShRtPTRm; ptcz=ecbc4e5a9a0a8080c895c9ab251feefc1cb96f09c17a60aa929d5373101e15b8; tvfe_boss_uuid=eb2ea47d83428ff4; _qpsvr_localtk=0.14182216620082677; pgv_info=ssid=s1077434965; uin=o1439237913; skey=@oPR3Iifmu; p_uin=o1439237913; pt4_token=5dhcKSF-Sl5I1xgtPsqfnxoHocf1YQzuST7IozUXfAs_; p_skey=5UXsAw5Dnu7q846JeVHq2oMcC3O7klGyNdc4ssH67i0_; Loading=Yes; 1439237913_todaycount=0; 1439237913_totalcount=29489; qz_screen=1536x864; QZ_FE_WEBP_SUPPORT=1; cpu_performance_v8=1"

# 将cookie字符串转换为cookies参数所需的字典：
# cookie_list = cookie_str.split(";")
#
# cookie_dict = {}
#
# for cookie in cookie_list:
#     cookie_dict[cookie.split("=")[0]] = cookie.split("=")[1]
# 使用列表推导式一行代码搞定
cookie_dict = {cookie.split("=")[0]: cookie.split('=')[-1] for cookie in cookie_str.split('; ')}

# 请求头参数字典中携带cookie字符串
# cookies参数的使用方法
# response = requests.get(url, cookies)
response = requests.get(url, headers=headers, cookies=cookie_dict)

print(response.content.decode())
